// Learn cc.Class:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/class.html
//  - [English] http://docs.cocos2d-x.org/creator/manual/en/scripting/class.html
// Learn Attribute:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://docs.cocos2d-x.org/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] https://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html

cc.Class({
    extends: cc.Component,

    properties: {
        m_ProgressBar:cc.ProgressBar,
        taskGoldLabel:cc.Label,
    },

    // LIFE-CYCLE CALLBACKS:

    moveOut() {
        this.node.runAction(cc.moveTo(0.5, 532, -14)).easing(cc.easeBackIn());
    },
    moveIn() {
        this.node.runAction(cc.moveTo(0.5, 369, -14)).easing(cc.easeBackInOut());
    },
    play() {

    },
    start() {

    },
    getGold() {
        // console.log('获取金币');
        // console.log(this.node.x, this.node.y);
        let goldAward = gDataCtrl.GetTaskGold();
        console.log('goldAward',goldAward);
        gameCtrl.createGoldAnima(this.node.position, cc.v2(-370, 680), 300, 15,goldAward,function(){
            gDataCtrl.clearTaskGold();
        });

        // console.log(gDataCtrl);


    },
    //进度条动画


    update (dt) { //dt是两帧的时间间隔，单位是s
        // let time = 3;
        let time = gDataCtrl.getGoldTime();
        // console.log(time);
        let ds =1/time;
        ds *= dt;
        this.m_ProgressBar.progress +=ds;
        if( this.m_ProgressBar.progress>=1){
            gDataCtrl.setAwardGold(3);
            let gold = gDataCtrl.getAwardGold();
            // console.log(gold);
            gDataCtrl.AddTaskGold(gold);
            this.m_ProgressBar.progress = 0;
            this.updateView();
        }

    },
    updateView(){
        this.taskGoldLabel.string = goldCarraybit(gDataCtrl.GetTaskGold());

    },
});